package com.nine.mymall.thirdservice.component;

import com.nine.mymall.thirdservice.utils.HttpUtils;
import lombok.Data;
import org.apache.http.HttpResponse;
import org.apache.http.entity.EntityTemplate;
import org.apache.http.util.EntityUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: duonine
 * @date: 2021/12/7
 */
@ConfigurationProperties(prefix = "spring.cloud.alicloud.sms")
@Data
@Component
public class SmsComponent {

    private String host;
    private String path;
    private String skin;
    private String sign;
    private String appcode;

    public void sendSmsCode(String phone, String code){
        String method = "GET";
        Map<String, String> headers = new HashMap<>();
        // 最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        // 根据API的要求，定义相对应的Content-Type
        Map<String, String> querys = new HashMap<>();
        querys.put("code", code);
        querys.put("phone", phone);
        querys.put("skin", "1");
        querys.put("sign", "1");

        try {
            System.out.println("短信发送成功了。。。。。。。。。。。。");
            //HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();

        }
    }

}
